'''
Created on 27/04/2012

@author: Bruna, Bruno
'''

from data_extractor import DataExtractor
from color_helper import calculate_rgb_normalized
import sys
    
def main():
    count_files = int(sys.argv[1])
    
    histograms = {}
    for index in xrange(2, count_files + 2):
        file_name = sys.argv[index]
        
        dataExtractor = DataExtractor(file_name)
        dataExtractor.extract_data()
        
        histograms[file_name] = dataExtractor.histogram

    while True:
        r = input()
        g = input()
        b = input()
        
        normalized_sample = calculate_rgb_normalized(r, g, b)
        
        maximized_probability = 0
        maximized_color = ''
        for histogram in histograms.keys():
            probability = histograms[histogram].probability(normalized_sample)
            if (probability > maximized_probability):
                maximized_probability = probability
                maximized_color = histogram
        
        print "Color is:", maximized_color, "with", maximized_probability
            
if __name__ == '__main__':
    main()